module derelict.newton.types;

extern(C):

alias double dFloat;

struct NewtonBody { }
struct NewtonWorld { }
struct NewtonJoint { }
struct NewtonContact { }
struct NewtonMaterial { }
struct NewtonCollision { }

struct NewtonRagDoll { }
struct NewtonRagDollBone { }

struct NewtonUserMeshCollisionCollideDesc {
	dFloat m_boxP0[4];						// lower bounding box of intersection query in local space
	dFloat m_boxP1[4];						// upper bounding box of intersection query in local space
	void* m_userData;                       // user data passed to the collison geometry at creation time
	int	  m_faceCount;                      // the applycation should set here how many polygons inteset the query
	dFloat* m_vertex;                        // the applycation should the pointer to the vertex array. 
	int m_vertexStrideInBytes;              // the applycation should set here the size of each vertex
	int* m_userAttribute;                   // the applycation should set here the pointer to the user data, one for each face
	int* m_faceIndexCount;                  // the applycation should set here the pointer to the vertex count of each face.
	int* m_faceVertexIndex;                 // the applycation should set here the pointer index array for each vertex on a face.
	NewtonBody* m_objBody;                  // pointer to the colliding body_
	NewtonBody* m_polySoupBody;             // pointer to the rigid body_ owner of this collision tree 
}

struct NewtonUserMeshCollisionRayHitDesc {
	dFloat m_p0[4];							// ray origin in collision local space
	dFloat m_p1[4];                          // ray destination in collision local space   
	dFloat m_normalOut[4];					// copy here the normal at the rat intesection
	int m_userIdOut;                        // copy here a user defined id for further feedback  
	void* m_userData;                       // user data passed to the collison geometry at creation time
}

struct NewtonHingeSliderUpdateDesc {
	dFloat m_accel;
	dFloat m_minFriction;
	dFloat m_maxFriction;
	dFloat m_timestep;
}


// Newton callback functions
alias void* function(int sizeInBytes) NewtonAllocMemory;
alias void function(void *ptr, int sizeInBytes) NewtonFreeMemory;

alias void function(void* serializeHandle, const void* buffer, size_t size) NewtonSerialize;
alias void function(void* serializeHandle, void* buffer, size_t size) NewtonDeserialize;


alias void function(NewtonUserMeshCollisionCollideDesc* collideDescData) NewtonUserMeshCollisionCollideCallback;
alias dFloat function(NewtonUserMeshCollisionRayHitDesc* lineDescData) NewtonUserMeshCollisionRayHitCallback;
alias void function(void* descData) NewtonUserMeshCollisionDestroyCallback;
alias void function(const NewtonBody* bodyWithTreeCollision, const NewtonBody* body_,
	const dFloat* vertex, int vertexstrideInBytes, int indexCount,
	const int* indexArray
	) NewtonTreeCollisionCallback;

alias void function(const NewtonBody* body_) NewtonBodyDestructor;
alias void function(const NewtonBody* body_) NewtonApplyForceAndTorque;
alias void function(const NewtonBody* body_, uint state) NewtonBodyActivationState;
alias void function(const NewtonBody* body_, const dFloat* matrix) NewtonSetTransform;
alias void function(const NewtonRagDollBone* bone) NewtonSetRagDollTransform;
alias void function(void *context, const dFloat* globalSpaceMatrix, dFloat* globalSpacePlane) NewtonGetBuoyancyPlane;

alias void function(const NewtonJoint* vehicle) NewtonVehicleTireUpdate;


alias dFloat function(const NewtonBody* body_, const dFloat* hitNormal, int collisionID, void* userData, dFloat intersetParam) NewtonWorldRayFilterCallback;
alias void function(const NewtonBody* body_) NewtonBodyLeaveWorld;

alias int  function(const NewtonMaterial* material, const NewtonBody* body0, const NewtonBody* body1) NewtonContactBegin;
alias int  function(const NewtonMaterial* material, const NewtonContact* contact) NewtonContactProcess;
alias void function(const NewtonMaterial* material) NewtonContactEnd;


alias void function(const NewtonBody* body_) NewtonBodyIterator;
alias void function(const NewtonBody* body_, int vertexCount, const dFloat* FaceArray, int faceId) NewtonCollisionIterator;


alias void function(const NewtonJoint* ball) NewtonBallCallBack;
alias uint function(const NewtonJoint* hinge, NewtonHingeSliderUpdateDesc* desc) NewtonHingeCallBack;
alias uint function(const NewtonJoint* slider, NewtonHingeSliderUpdateDesc* desc) NewtonSliderCallBack;
alias uint function(const NewtonJoint* universal, NewtonHingeSliderUpdateDesc* desc) NewtonUniversalCallBack;
alias uint function(const NewtonJoint* corkscrew, NewtonHingeSliderUpdateDesc* desc) NewtonCorkscrewCallBack;
alias void function(const NewtonJoint* userJoint) NewtonUserBilateralCallBack;

alias void function(const NewtonJoint* me) NewtonConstraintDestructor;
